package edu.pku.sei.transformation.editor.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.ui.PartInitException;

import edu.pku.sei.transformation.editor.model.implement.TransformationCode;
import edu.pku.sei.transformation.editor.views.editor.TextEditor;
import edu.pku.sei.transformation.editor.views.icons.IconsProvider;

public class ViewCodeAction extends Action{
	TransformationCode code = null;
	public ViewCodeAction(TransformationCode code) {
		this.code = code;
		this.setText(code.getLanguage());
		this.setImageDescriptor(IconsProvider.getImageDescriptor(IconsProvider.FILE_ICO));
	}
	
	@Override
	public boolean isEnabled() {
		if (code == null) {
			return false;
		}
		return true;
	}
	
	@Override
	public void run() {
		try {
			TextEditor.openInEditor(code.getFile());
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}
}